package com.yenlien.traceyun.usercenter.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.yenlien.traceyun.webase.entity.BaseEntity;

import javax.persistence.*;
import java.util.Date;
import java.util.List;

/**
 * @author: bigwangy@sina.com
 * @create: 2020-03-04
 * @description:用户
 **/

@Entity
@Table(name = "t_user")
public class User extends BaseEntity {

    public enum UserType {
        ADMIN, //管理员
        COMPANY, //企业用户
        GOV,//政府用户
        AGENT,//代理商
        COMMON //普通用户
    }

    private String isManage;    // 1=西昌冷链后台系统管理员, 2=不是西仓冷链管理员  3=水果 4=农资   该字段有值则代表是西仓冷链系统的用户，companyId也就是ColdStorageComp的Id

    @Column(name = "company_id", length = 32)
    private String companyId;  //企业id
    @Column(name = "department_id", length = 32)
    private String departmentId;  //部门id
    @Transient
    private String department;
    //姓名
    @Column(name = "name", length = 255)
    private String name;
    //登录名
    @Column(name = "username", length = 255)
    private String username;

    //密码
    @Column(name = "password", length = 32)
    private String password;

    //性别
    @Column(name = "gender", length = 10)
    private String gender;

    @Column(name = "id_card", length = 18)
    private String idCard; //身份证号码

    //手机
    @Column(name = "phone", length = 13)
    private String phone;

    //邮箱
    @Column(name = "email", length = 50)
    private String email;

    //用户类型
    @Enumerated(EnumType.STRING)
    @Column(name = "user_type", length = 10)
    private UserType userType;

    //创建时间
    @JsonIgnore
    @Column(name = "createtime")
    public Date createtime;

    //更新时间
    @JsonIgnore
    @Column(name = "updatetime")
    public Date updatetime;

    //账号是否被锁定
    @Column(name = "locked")
    private boolean locked;

    @Column
    private String headImg;      //头像

    @Column
    private String loginId;  //单点登录id

    @Column(name = "education", length = 10)
    private String education;    //学历

    @Column(name = "jobtime")
    private String jobtime;    //入职时间
    @Transient
    private List<UserResource> userMenus;//人员权限
    @Transient
    private String query;


    public String getIsManage() {
        return isManage;
    }

    public void setIsManage(String isManage) {
        this.isManage = isManage;
    }

    public String getQuery() {
        return query;
    }

    public void setQuery(String query) {
        this.query = query;
    }

    public String getDepartment() {
        return department;
    }

    public void setDepartment(String department) {
        this.department = department;
    }

    public String getCompanyId() {
        return companyId;
    }

    public void setCompanyId(String companyId) {
        this.companyId = companyId;
    }

    public String getDepartmentId() {
        return departmentId;
    }

    public void setDepartmentId(String departmentId) {
        this.departmentId = departmentId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<UserResource> getUserMenus() {
        return userMenus;
    }

    public String getLoginId() {
        return loginId;
    }

    public void setLoginId(String loginId) {
        this.loginId = loginId;
    }

    public void setUserMenus(List<UserResource> userMenus) {
        this.userMenus = userMenus;
    }

    public String getIdCard() {
        return idCard;
    }

    public void setIdCard(String idCard) {
        this.idCard = idCard;
    }

    public String getEducation() {
        return education;
    }

    public void setEducation(String education) {
        this.education = education;
    }

    public String getJobtime() {
        return jobtime;
    }

    public void setJobtime(String jobtime) {
        this.jobtime = jobtime;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public Date getCreatetime() {
        return createtime;
    }

    public void setCreatetime(Date createtime) {
        this.createtime = createtime;
    }

    public Date getUpdatetime() {
        return updatetime;
    }

    public void setUpdatetime(Date updatetime) {
        this.updatetime = updatetime;
    }

    public boolean isLocked() {
        return locked;
    }

    public void setLocked(boolean locked) {
        this.locked = locked;
    }

    public String getHeadImg() {
        return headImg;
    }

    public void setHeadImg(String headImg) {
        this.headImg = headImg;
    }

    public UserType getUserType() {
        return userType;
    }

    public void setUserType(UserType userType) {
        this.userType = userType;
    }

    /**
     * 根据第三方的数据,将状态转换为我们的枚举类型
     * @param type
     * @return
     */
    public UserType verdictType(String type) {
        UserType userType;
        switch (type) {
            case "1":
                userType = UserType.ADMIN;
                break;
            case "2":
                userType = UserType.COMMON;
                break;
            default:
                throw new IllegalArgumentException("Unknown enum value: " + type);
        }
        return userType;
    }
}
